﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Microsoft.Practices.Unity;
using Vit.Common;
using Vit.Common.Providers;
using Vit.Common.Extensions;
using Vit.Web;
using Vit.Web.Models;
using Vit.Web.Providers;
using Vit.Web.Mvc.Results;

namespace Vit.AdminModule.Areas.Admin.Controllers
{
    public class LogController : Vit.Web.Mvc.Controllers.DataControllerBase<Vit.Web.Models.Log>
    {
        public ActionResult RemoveAll(string id)
        {
            DateTime dt = DateTime.Today;
            if (!string.IsNullOrWhiteSpace(id))
                DateTime.TryParse(id, out dt);
            Unity.Current.ResolveAny<ILogProvider>().ForEach<ILogProvider>(p => p.RemoveAll(dt));
            return Refresh();
        }

        public ActionResult Clear()
        {
            Unity.Current.ResolveAny<ILogProvider>().ForEach<ILogProvider>(p => p.Clear());
            ViewBag.Message = "Logs Cleared!";
            return GoBack();
        }
    }
}
